package com.flower.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.flower.domain.dto.admin.LogDto;
import com.flower.domain.entity.SysLog;
import com.flower.service.LogService;
import com.flower.mapper.LogMapper;
import com.flower.domain.vo.PageVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
* @author 86178
* @description 针对表【log(操作日志表)】的数据库操作Service实现
* @createDate 2025-02-20 09:41:25
*/
@Service
public class LogServiceImpl extends ServiceImpl<LogMapper, SysLog>
    implements LogService{

    @Override
    public PageVO<SysLog> pageList(LogDto logDto) {
        // 创建Page实例
        Page<SysLog> logPage = new Page<>(logDto.getPageNumber(), logDto.getPageSize());

        // 创建查询条件
        LambdaQueryWrapper<SysLog> queryWrapper = new LambdaQueryWrapper<>();

        // 添加搜索条件，使用动态SQL
        queryWrapper.like(StringUtils.isNotBlank(logDto.getName()),
                        SysLog::getName, logDto.getName())
                    .like(StringUtils.isNotBlank(logDto.getUsername()),
                            SysLog::getUsername, logDto.getUsername())
                    .like(StringUtils.isNotBlank(logDto.getIp()),
                            SysLog::getIp, logDto.getIp());

        // 执行查询
        Page<SysLog> page = page(logPage, queryWrapper);

        // 转换为PageVO
        PageVO<SysLog> pageVO = new PageVO<>();
        BeanUtils.copyProperties(page, pageVO);
        return pageVO;
    }
}




